package com.ecnu.sei.app.course;

import com.ecnu.sei.app.resources.Classroom;
import com.ecnu.sei.app.resources.Time;
import com.ecnu.sei.app.teacher.Official;
import com.ecnu.sei.app.util.Pair;
import com.ecnu.sei.app.util.Utils.CollegeYear;

public class CompulsoryCourse extends AbstractCourse {

  public CompulsoryCourse(CourseInfo info) {
    super(info);
  }
  
  @Override
  public boolean setResource() { 
    Pair<Time, Classroom> resource = scheduler.getFreeResource(info.getCollegeYear());

    if (resource != null) {
      setResource(resource);
      return true;
    }
    return false; 
  }

  private void setResource(Pair<Time, Classroom> resource) {
    ExamInfo examInfo = info.getExamInfo();
    examInfo.setTime(resource.getFirst())
            .setClassroom(resource.getSecond());
  }

  @Override
  public boolean setResourcePending() { 
    for (CollegeYear collegeYear : CollegeYear.getList()) {
      Pair<Time, Classroom> resource = scheduler.getFreeResource(collegeYear);
      if (resource != null) {
        setResource(resource);
        return true;
      }
    }
    return false;
  }

  @Override
  public boolean setPatrol(Official patrol) {
      if (patrol.isAvailableForPatrol(this)) {
        ExamInfo examInfo = info.getExamInfo();
        examInfo.setPatrol(patrol);
/*        patrol.addProctor(this);
*/        return true;
      } else {
        return false;
      }

  } 
  

}
